package com.itlong.cloud.app.service.impl;

import com.itlong.cloud.POJO.DTO.app.AppGetParkingListDTO;
import com.itlong.cloud.POJO.VO.app.AppGetParkingDateVO;
import com.itlong.cloud.POJO.VO.app.AppGetParkingListVO;
import com.itlong.cloud.POJO.VO.app.AppParkingRecordVO;
import com.itlong.cloud.app.dao.IAppParkRecordDao;
import com.itlong.cloud.app.service.IAppParkRecordService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      停车记录服务层接口实现类
 * <desc/>
 *
 * @createDate 2018/11/08
 */
@Service
public class AppParkRecordServiceImpl implements IAppParkRecordService {

    @Autowired
    private IAppParkRecordDao iAppParkRecordDao;

    /**
     * <desc>
     *      获取用户停车记录列表
     * </desc>
     *
     * @return 用户停车记录列表
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public AppGetParkingListVO getParkingList(AppGetParkingListDTO appGetParkingListDTO) throws Exception {
        AppGetParkingListVO appGetParkingListVO = new AppGetParkingListVO();
        Map<String ,Object> params = SqlUtil.convertBeanToMapParams(appGetParkingListDTO);
        Integer pageIndex = (StringHandlerUtil.strToIntDef(appGetParkingListDTO.getPageNum(),1) - 1) * 15;
        params.put("pageIndex",pageIndex);
        List<AppParkingRecordVO> appParkingRecordVOList = iAppParkRecordDao.getParkingList(params);
        Integer pageCount = 0;
        if (appParkingRecordVOList != null && !appParkingRecordVOList.isEmpty()) {
            for (AppParkingRecordVO appParkingRecordVO : appParkingRecordVOList){
                pageCount += appParkingRecordVO.getRecordAry().size();
            }
            appGetParkingListVO.setPageCount(pageCount + "");
            appGetParkingListVO.setDataAry(appParkingRecordVOList);
        }
        return appGetParkingListVO;
    }

    /**
     * <desc>
     *      获取该用户停车记录列表有效查询时间
     * </desc>
     *
     * @return 该用户停车记录列表有效查询时间
     * @author wanghzi
     * @createDate 2018/11/09
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<AppGetParkingDateVO> getParkingDateList(String carNum,String userId) throws Exception {
        List<AppGetParkingDateVO> appGetParkingDateVOList = iAppParkRecordDao.getParkingDateList(carNum,userId);
        return appGetParkingDateVOList;
    }
}
